<?php
/**
 * @version $Id: specialtype.php 21 2010-05-14 13:24:08Z vladzimirs $
 * @package UnoCart
 * @copyright Авторские права (C) 2009-2010 UnoCart team & (C) 2007-2010 Joostina team &. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * UnoCart! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл help/copyright.php.
 */
defined('_VALID_MOS') or die('Restricted access');
class JSpecial_type_prod
{
    function showBackend()
    {
    }
    function delete()
    {
    }
    function save()
    {
    }
    // Music attribute
}

class JSpecial_1 extends JSpecial_type_prod
{
    function showBackend($product)
    {
        $values = $product->getSpecialType();

?>
				<table width = "100%" align = "left">
					<tr>
						<th align = "left">
							<?php

        echo _UNOCART_SPECIAL_MUSIC_NUMBER_TRACK;

?>						
						</th>
						<th align = "left">
							<?php

        echo _UNOCART_SPECIAL_MUSIC_TITLE;

?>
						</th>
						<th align = "left">
							<?php

        echo _UNOCART_SPECIAL_MUSIC_TIME;

?>
						</th>
						<th align = "left">
							<?php

        echo _UNOCART_SPECIAL_MUSIC_PREVIEW;

?>						
						</th>
						<th>
							<?php

        echo _UNOCART_DELETE

?>
						</th>
					</tr>
				<?php

        if (count($values))
            foreach ($values as $value) {

?>
					<tr>
						<td width = "10%">
							<?php

                echo $value->field_1

?>
						</td>
						<td width = "20%">
							<?php

                echo $value->field_2

?>	
						</td>
						<td width = "20%">
							<?php

                echo $value->field_3

?>	
						</td>
						<td width = "20%">
							<?php

                echo $value->field_4

?>	
						</td>
						<td>
							<input type = "checkbox" name = "delete[<?php

                echo $value->value_id

?>]" value = "1" />
						</td>
						<td>
						</td>
					</tr>
				<?php

            }

?>
				<tr id = "last_tr">
					<td colspan = "5"><a href = "#" onclick = "addExtendField(); return false"><?php

        echo _UNOCART_ADD_VALUE

?></span></td>
				</tr>
				</table>
			<?php

    }

    function save($product_id)
    {
        global $database, $unocartConfig;
        $count = count($_POST['title']);
        $files = $_FILES['files'];
        foreach ($_POST['title'] as $key => $value) {
            $j = 0;
            $count = count($_FILES['files']['name']);
            if ($files['size'][$key]) {
                $file_name = $unocartConfig->other_files_path . Jstring::str_ireplace(array(" ", "'", '"',
                    "-"), "", $files['name'][$key]);
                do {
                    if (!file_exists($file_name)) {
                        if (move_uploaded_file($files['tmp_name'][$key], $file_name)) {
                            break;
                        } else {
                            echo "error uploading file";
                            die();
                        }
                    } else {
                        $file_name = $unocartConfig->files_path . $j++ . "_" . Jstring::str_ireplace(array(" ",
                            "'", '"', "-"), "", $files['name'][$key]);
                    }
                } while (1);
            }
            $query = "INSERT INTO `#__unocart_products_sp_type_info`
				          SET `product_id` = '" . $product_id . "',
						  	  `field_1` = '" . $_POST['number'][$key] . "',
							  `field_2` = '" . $_POST['title'][$key] . "',
							  `field_3` = '" . $_POST['time'][$key] . "',
							  `field_4` = '" . basename($file_name) . "'";
            $database->setQuery($query);
            $database->query();
        }
    }

    function delete($array_delete)
    {
        global $database, $unocartConfig;
        foreach ($array_delete as $key => $value) {
            $query = "SELECT sp_type.field_4
				          FROM `#__unocart_products_sp_type_info` AS sp_type
						  WHERE sp_type.value_id = '" . $key . "'";
            $database->setQuery($query);
            @unlink($unocartConfig->files_path . $file = $database->loadResult());

            $query = "DELETE FROM `#__unocart_products_sp_type_info`
				          WHERE `value_id` = '" . $key . "'";
            $database->setQuery($query);
            $database->query();
        }
    }
}

?>